﻿/*
 * @Autor: PK
 * @Date: 2022/01/15 09:26:SS
 */

using System;
using System.Collections.Generic;
using System.Linq;
using ShkSimulation.core.template;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.customer;

namespace ShkSimulation.highway {

	public class VehicleInputManager: LambdaDemandManager {

		public VehicleInputManager() : base(CreateTemplate) {
		}

		public static TimeSpan ArriveSpan => TimeSpan.FromDays(1 / HighwayRunConfig.DayArriveCount);

		private static List<CustomerTemplate> CreateTemplate(NetworkInputData inputData) {
			// 只有一种输入流模板，依次经过所有路段，路段通过id决定前后顺序，实际使用时可以不按这个逻辑
			IReadOnlyDictionary<int, Agency> sections = inputData.AllAgencies;
			List<CustomerTemplate> result = new List<CustomerTemplate>();
			List<Agency> agencies = sections.Values.OrderBy(agencyOrder => agencyOrder.Order).ToList();
			for (var i = 0; i < agencies.Count; i++) {
				RoadSection section = (RoadSection)agencies[i];
				if (i != 0) {
					section.LastSection = (RoadSection)agencies[i - 1];
				}
				if (i != agencies.Count - 1) {
					section.NextSection = (RoadSection)agencies[i + 1];
				}
			}
			string uniqueKey = "唯一种类输入流";
			result.Add(new VehicleTemplate(uniqueKey, agencies, ArriveSpan));
			return result;
		}


	}

}